package com.base.myproject.client.HR.setting;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.Widget;

public class HR_hourPay_Setting extends BaseJDBCPanel{
	public HR_hourPay_Setting()
	{
		init();
		
	}
	public void init()
	{
		add(initWeigetx());
		registerMainStore(store);
		registerStore(store);
		//setdefault();

	}
	private Widget initWeigetx()
	{
		VerticalPanel vpanel = new VerticalPanel();
		vpanel.add(createGrid());
		return vpanel;
		
	}
	
	BaseStore<BusiObject> store = null;
	BaseStore<BusiObject> getStore(){
	if(store==null) 
	{
		createStore();
	}
	return store;}
	BaseStore<BusiObject> createStore(){
	ModelType type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record");
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("hourMoney");
	type.getField("hourMoney").setType(Double.class);
	type.addField("isuse");
	type.getField("isuse").setType(Boolean.class);
	type.addField("hourEndDate");
	type.getField("hourEndDate").setType(Date.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("hr_helper_hourPay");
	info.setKeyname(new String[] { "icode"});
	info.setSql("select * from hr_helper_hourPay");
	  store = new BaseStore<BusiObject>(type, info);
	 return store;
	 }
	
	BaseGridPanel grid=null;
	BaseGridPanel getgrid(){
		if(grid==null) 
		{
			createGrid();
		}
		return grid;}
	
	BaseGridPanel createGrid(){
	CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
	List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
	columns.add(cbs.getColumn());

	//ColumnConfig C1 = new ColumnConfig("icode", "icode", 80);
	//columns.add(C1);
	ColumnConfig C2 = new ColumnConfig("hourMoney", "时薪", 80);
	NumberField C_num2 = new NumberField();
	C_num2.setPropertyEditorType(Long.class);
	C2.setEditor(new CellEditor(C_num2));
	columns.add(C2);
	
	ColumnConfig C3 = new ColumnConfig("hourEndDate", "截止时间", 120);
	DateField C_data3 = new DateField();
	C_data3.getPropertyEditor().setFormat(
			DateTimeFormat.getFormat("yyyy-MM-dd"));
	C3.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
	C3.setEditor(new CellEditor(C_data3));
	columns.add(C3);
	
	ColumnConfig C4 = new ColumnConfig("isuse", "是否启用", 120);
	C4.setEditor(new CellEditor(new CheckBox()));
	columns.add(C4);

	ColumnModel cm = new ColumnModel(columns);
	grid = new BaseGridPanel(getStore(), cm,true,true);
	cbs.setSelectionMode(SelectionMode.SINGLE);
	grid.getBg().setSelectionModel(cbs);
	grid.setHeight(150);
	grid.setWidth(400);
	return grid ;
	}
}
